package com.hnit.care.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hnit.care.entity.Coredata;
import com.hnit.care.entity.Weather;
import com.hnit.care.entity.vo.AppData;
import com.hnit.care.mapper.CoredataMapper;
import com.hnit.care.netty.NettyServerHandler;
import com.hnit.care.service.ICoredataService;
import com.hnit.care.util.WeatherUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author liang
 * @since 2023-07-24
 */
@Service
public class CoredataServiceImpl extends ServiceImpl<CoredataMapper, Coredata> implements ICoredataService {

    @Resource
    private CoredataMapper CoredataMapper;

    @Resource
    private NettyServerHandler nettyServerHandler;


    @Override
    public List<Coredata> getCoredataList() {
        List<Coredata> Coredata = baseMapper.selectList(null);
        return Coredata;
    }

    @Override
    public void manageAppData(AppData appData) {
        /**
         * 拿到数据该存到存到数据库，该转发给硬件的转发给硬件
         */
        //存数据库
        Coredata Coredata = new Coredata();

        //转发到硬件，这里需要做帧数据的拼接
        String message = null;
        nettyServerHandler.doAllReplay(message);

    }

    @Override
    public List<Weather> getInfo() {
        //拿到数据封装成List返回
        Weather weather = WeatherUtils.getWeather();

        List<Weather> weatherList = new ArrayList<>();

        weatherList.add(weather);

        return weatherList;
    }

    @Override
    public List<Coredata> getGyInfo() {
        //直接从数据库中拿，封装到List返回就好啦
        List<Coredata> coredata = baseMapper.selectList(null);
        return coredata;
    }
}
